#! /usr/bin/python3
# -*- coding: UTF-8 -*-

if __name__ == "__main__":
	raise Exception("不支持从这里调用")

__version__ = "1.0"
__all__ = ["RunAuthEmbedServerCmd"]

import re

from com.mousechsh.common.cmd.MouseChshCmd import MouseChshCmd, mousechsh_cmd_annotation
from com.mousechsh.common.log.MouseChshLog import MOUSECHSH_LOG_LEVEL_WARN, mousechsh_logging_exception
from com.mousechsh.common.middle.http.MouseChshInnerHttpWrapper import MouseChshInnerHttpWrapper


@mousechsh_cmd_annotation()
class RunAuthEmbedServerCmd(MouseChshCmd):
	__prefix = ''

	def reference(self):
		return [
			'com.mousechsh.business.conf.MouseChshBusinessConfig',
			'com.mousechsh.business.app.auth.MouseChshAuthApi'
		]

	def command(self):
		return 'auth-server'

	def parse(self, *params):
		for item in params:
			if re.match('--prefix=', item):
				self.__prefix = item[9:]

	def run(self):
		try:
			self.object = MouseChshInnerHttpWrapper()
			self.object.disable_handler()
			self.object.set_path_prefix(self.__prefix)
			self.object.run()
		except Exception as ex:
			mousechsh_logging_exception(ex, "遇到无法恢复的错误：", level=MOUSECHSH_LOG_LEVEL_WARN)

	def interrupt(self):
		self.object.close()

	def call(self, *args_arr, **args_dict):
		return self.object.call(args_arr[0])
